← Projects

Router API

06/2022 - 08/2022

Tech Stack:

https://cdn.jsdelivr.net/gh/devicons/devicon@latest/icons/flask/flask-original.svg
https://cdn.jsdelivr.net/gh/devicons/devicon@latest/icons/python/python-original.svg
GitHub:   Private

Description: An internal API that is used by Curbhub for Router


Description:

This purporse of this project is to set up a website API that can be called by any services to use the Curbhub's Router without having to enage with the Router code.

Overview:

The API will be receving all the order-related and fleet related information and return a list of stops with stop ID, and their arrival and departure time in JSON format. User would need to follow rules to be able to call the RouterAPI succesfully.

Resource

GET https://www.curbhub.io/api/1.0/trips

Trips Parameter

Required

  • Deliveryorder (deliveryorder)
    • Each delivery order contains one pick up location and multiple drop-off location. Pick up location contains pickup time, id, and coordinates.
  • Pickup_time (day-month-year-hour:minute)
    • The time to pick up the delivery orders at a location in the following format %d-%m-%y-%H:%M
  • Pickup_id (pid)
    • The unique Pickup location id
  • Pickup_loc (ploc)
    • Geographical coordinates of Pickup location with latitude and longitude
  • Drop-off
    • Drop off contains information about multiple drop off delivery orders.
  • num_of_packages (npack)
    • the number of packages needed to drop off at an specific location
  • Drop-off loc_id (did)
    • The unique Drop-off location id
  • Drop-off location (lat%7Clong)
    • Geographical coordinates of Drop-off location with latitude and longitude
  • first_leg_cap (firstlc)
    • Capacity of the first leg couriers

Optional

  • Second_leg_couriers (secondlc) - contains information about the service area, capacity and type of the second leg transportation
  • service_area - Geographical coordinates of service area for second leg couriers with latitude and longitude
  • capacity (cap) - Capacity of the second leg couriers
  • type (type) - The unique type of transportation for the second leg couriers
  • transship_loc (tloc) - Geographical coordinates of transship points, the location where first leg couriers transfers the packages to second leg couriers

Template Request

* ? is used to separate path and query parameter 
* & is used to separate each query parameter `
* % 7C is the separator to separate individual variable(|)
   - Ex. [10, 20, 30] -> 10 % 7C20 % 7C30 -> 10 | 20 | 30
* % 2C is the separator to separate items in a list(,)
- Ex. [(10, 20), (30, 40)] -> 10 % 7C20 % 2C30 % 7C40 -> -> 10 | 20, 30 | 40
* % 20 is the separator to separate the delivery orders(' ')
- Ex.deliveryorder={ order1 } % 20{ order2 } -> deliveryorder={ order1 } { order2 }
https://www.curbhub.io/api/1.0/trips?deliveryorder={day-month-year-hour:minute}%7C
                                                       {id}%7C
                                                       {lat%7Clong}%7C
                                                       {npack1%7Cdid1%7Clat1%7Clong1%2C
                                                       npack2%7Cdid2%7Clat2%7Clong2...}%20
                                                       {day-month-year-hour:minute}%7C
                                                       {id}%7C
                                                       {lat%7Clong}%7C
                                                       {npack1%7Cdid1%7Clat1%7Clong1%2C
                                                       npack2%7Cdid2%7Clat2%7Clong2...}....
                                       &firstlc={n1%7Cn2%7Cn3%7C...}
                                       &secondlc={lat1%7Clong1%7Ccap1%7Ctype1%2C
                                                  lat2%7Clong2%7Ccap2%7Ctype2%2C...}
                                       &tloc={lat1%7Clong1%2C
                                              lat2%7Clong2%2C
                                              lat3%7Clong3…}
   

Example Request

We have the following inputs

   deliveryorders:
      order1:
         pickup_id: '12'
         pickup_time: '11-6-22-13:00'
         pickup_location: (-69.0082, 153.2198)
         dropoffs:
            - drop off location1:
                  num_of_packages: 3
                  loc_id: '13'
                  loc: (29.7227, 33.2767)
            - drop off location2:
                  num_of_packages: 1
                  loc_id: '14'
                  loc: (2.9799, 43.9455)
      order2:
         pickup_id: '15'
         pickup_time: '11-6-22-18:00'
         pickup_location: (-70.123, 150.312)
         dropoffs:
            - drop off location1:
                  num_of_packages: 2
                  loc_id: '17'
                  loc: (29.7227, 33.2767)
                  
   first_leg_capacity: 
         capacity1: 10
         capacity2: 20
         capacity3: 10
   
   second_leg_couriers:
         courier1:
            - service_area : (-76.7788, 6.6568)
            - capacity : 5
            - type : bike
         courier2:
            - service_area : (-34.1809, 115.2988)
            - capacity : 5
            - type : bike
    transship location:
           tranship1: (-58.8951, -0.1513)
           tranship2: (11.5015, 88.7465)
   

Converting the example inputs with the template

Remove the space before calling the website

 https://www.curbhub.io/api/1.0/trips?deliveryorder=11-6-22-13:00%7C
                                                    12%7C
                                                    -69.0082%7C%153.2198%7C
                                                    3%7C13%7C29.7227%7C33.2767%2C
                                                    1%7C14%7C2.9799%7C43.9455%20
                                                    11-6-22-18:00%7C
                                                    15%7C
                                                    -70.123%7C150.312%7C
                                                    2%7C17%7C29.7227%7C33.2767
                                    &firstlc=10%7C20%7C30
                                    &secondlc=-76.7788%7C6.6568%7C5%7Cbike%2C
                                              -34.1809%7C115.2988%7C5%7Cbike
                                    &tloc=-58.8951%7C-0.1513%2C
                                           11.5015%7C88.7465
 https://www.curbhub.io/api/1.0/trips?deliveryorder=11-6-22-13:00%7C12%7C-69.0082%7C153.2198%7C3%7C13%7C29.7227%7C33.2767%2C1%7C14%7C2.9799%7C43.9455%20
 11-6-22-18:00%7C15%7C-70.123%7C150.312%7C2%7C17%7C29.7227%7C33.2767&firstlc=10%7C20%7C30&secondlc=-76.7788%7C6.6568%7C5%7Cbike%2C34.1809%7C115.2988%7C5%7Cbike&tloc=-58.8951%7C-0.1513%2C11.5015%7C88.7465

Technologies

Project is created with:

  • PyCharm v 2022.1.2
  • Postman v 9.23.3
  • Python v 3.9
  • Flask v 2.1

Tools

Libriaies that are used:

  • datetime
  • unittest
  • requests
  • Flask
  • jsonify
  • make_response

Set up

To run this project, use the follwing command:

  flask run